package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/lab-online/internal/course/constant"
	"github.com/lab-online/internal/course/entity"
	mw "github.com/lab-online/pkg/middleware"
	"github.com/lab-online/pkg/resp"
)

type RemoveCourseReqParams struct {
	ID uint `uri:"id" binding:"required,min=1" example:"1"` // 课程id
}

var RemoveCourseValidator = mw.NewValidator(func() *mw.ValidatorOptions {
	return &mw.ValidatorOptions{
		Params: &RemoveCourseReqParams{},
	}
})

type RemoveCourseRespBody struct {
	resp.BaseRespBody
}

// RemoveCourse 删除课程
//
//	@Summary				删除课程
//	@Description			管理员可以删除课程
//	@Description.markdown	RemoveCourse
//	@Tags					course
//	@Accept					json
//	@Produce				json
//	@Security				bearer
//	@Param					Authorization	header		string	true	"`admin`"
//	@Param					id				path		uint	true	"课程id"
//	@Success				201				{object}	RemoveCourseRespBody
//	@Failure				400				{object}	resp.FailedRespBodyString
//	@Failure				403				{object}	resp.FailedRespBodyString
//	@Failure				500				{object}	resp.FailedRespBodyString
//	@x-apifox-status		"developing"
//	@Router					/v1/courses/:id	[delete]
func (h *Handler) RemoveCourse(c *gin.Context) {
	id := c.MustGet(mw.KeyParams).(*RemoveCourseReqParams).ID
	courseEntity := entity.NewCourseEntity(entity.WithID(id))

	if err := h.domain.RemoveCourse(courseEntity); err != nil {
		resp.ErrorHandler(c, err)
	} else {
		resp.Success[any](c, constant.CodeRemoveCourseSuccess)
	}
}
